home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / linux / src / atalnx_3.lzh / atari-linux-0.01pl3 / atari / atapart.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  2.9 KB  |  120 lines

  1. /*
  2.  * linux/atari/atapart.c
  3.  *
  4.  * Atari partition checking driver for 680x0 Linux
  5.  * Written by Andreas Schwab (schwab@ls5.informatik.uni-dortmund.de)
  6.  *
  7.  * 5/3/94 Roman Hodek:
  8.  *   Added some sanity checks
  9.  *   Linux device names start from 1 not 0, so I changed the initial value
  10.  *   for i to 1.
  11.  *
  12.  * This file is subject to the terms and conditions of the GNU General Public
  13.  * License.  See the file README.legal in the main directory of this archive
  14.  * for more details.
  15.  */
  16.  
  17. #include <linux/config.h>
  18. #include <linux/fs.h>
  19. #include <linux/genhd.h>
  20. #include <linux/kernel.h>
  21.  
  22. #include <linux/atari_rootsec.h>
  23.  
  24. extern int current_minor;
  25.  
  26. void
  27. atari_check_partition (struct gendisk *hd, unsigned int dev)
  28. {
  29.   int i, minor = current_minor, m_lim = current_minor + hd->max_p;
  30.   struct buffer_head *bh;
  31.   struct rootsector *rs;
  32.   struct partition_info *pi;
  33.   ulong extensect;
  34.  
  35.   bh = bread (dev, 0, 1024);
  36.   if (!bh)
  37.     {
  38.       printk (" unable to read block 0\n");
  39.       return;
  40.     }
  41.  
  42.   rs = (struct rootsector *) bh->b_data;
  43.   printk ("  %s%c:", hd->major_name, 'a' + (minor >> hd->minor_shift));
  44.  
  45.   pi = &rs->part[0];
  46.   for (i = 1; pi < &rs->part[4] && minor < m_lim; i++, minor++, pi++)
  47.     {
  48.       if (pi->flg & 1)
  49.   /* active partition */
  50.   {
  51.     if (memcmp (pi->id, "XGM", 3) == 0)
  52.       /* extension partition */
  53.       {
  54.         struct rootsector *xrs;
  55.         struct buffer_head *xbh;
  56.         ulong partsect;
  57.  
  58.         partsect = extensect = pi->st;
  59.         while (1)
  60.       {
  61.         xbh = bread (dev, partsect / 2, 1024);
  62.         if (!xbh)
  63.           {
  64.             printk (" block %ld read failed\n", partsect);
  65.             return;
  66.           }
  67.         if (partsect & 1)
  68.           xrs = (struct rootsector *) &xbh->b_data[512];
  69.         else
  70.           xrs = (struct rootsector *) &xbh->b_data[0];
  71.  
  72.         /* ++roman: sanity check: bit 0 of flg field must be set */
  73.         if (!(xrs->part[0].flg & 1)) {
  74.             printk( "\nFirst sub-partition in extended partition is not valid!\n" );
  75.             break;
  76.         }
  77.         
  78.         hd->part[minor].start_sect = partsect + xrs->part[0].st;
  79.         hd->part[minor].nr_sects = xrs->part[0].siz;
  80.         printk (" %s%c%d", hd->major_name,
  81.             'a' + (minor >> hd->minor_shift), i);
  82.  
  83.         if (!(xrs->part[1].flg & 1)) {
  84.             /* end of linked partition list */
  85.             brelse( xbh );
  86.             break;
  87.         }
  88.         if (memcmp( xrs->part[1].id, "XGM", 3 ) != 0) {
  89.             printk( "\nID of extended partion is not XGM!\n" );
  90.             brelse( xbh );
  91.             break;
  92.         }
  93.         
  94.         partsect = xrs->part[1].st + extensect;
  95.         brelse (xbh);
  96.         i++;
  97.         minor++;
  98.         if (minor >= m_lim) {
  99.             printk( "\nMaximum number of partitions reached!\n" );
  100.             break;
  101.         }
  102.       }
  103.       }
  104.     else
  105.       {
  106.         /* we don't care about other id's */
  107.         hd->part[minor].start_sect = pi->st;
  108.         hd->part[minor].nr_sects = pi->siz;
  109.         printk (" %s%c%d", hd->major_name,
  110.             'a' + (minor >> hd->minor_shift), i);
  111.  
  112.       }
  113.   }
  114.     }
  115.   brelse (bh);
  116.  
  117.   printk ("\n");
  118. }
  119.  
  120.